//
//  TableView.swift
//  GreenDeal
//
//  Created by Moennig Q on 21/12/2022.
//

import UIKit

class TableView: UITableView {
    lazy var loadFaildView = DatalLoadFaildView()
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect, style: UITableView.Style = .plain) {
        super.init(frame: frame, style: style)
        self.separatorStyle = UITableViewCell.SeparatorStyle.none
        self.showsVerticalScrollIndicator = false
        self.setUpView()
        
    }
    func setUpView(){
        
    }
    //MARK: - 通用的load no data view
    func showResultView(nodataFlag: Bool,tipMsg: String = R.string.localizable.noResultsFound()){
        if nodataFlag  {//
            let noDataView = LoadNoDataView()
            noDataView.setTipMsg(tipMsg)
            noDataView.contentMode = .scaleAspectFit
            self.backgroundView = noDataView
        }else{
            self.backgroundView = nil
        }
        
    }
    //MARK: - 通用的Retry view
    func showRetryView(){
        //MARK: - 加载失败的view
        loadFaildView.contentMode = .scaleAspectFit
        self.backgroundView = loadFaildView
    }
}
extension TableView {
    //MARK: - calendar的load no data view
    func checkIfCalendarShowNoDataView(_ listCont: Int){
        if listCont > 0 {
            self.backgroundView = nil
        }else{
            let noDataView = CalendarNotDataView()
            noDataView.contentMode = .scaleAspectFit
            self.backgroundView = noDataView
        }
        
    }
}
